package day1

import kotlin.test.Test
import kotlin.test.assertEquals

class RepetitionsString {
    private fun repetitionsString(str: String): Int {
        for (length in str.length downTo 1) {
            Search@ for (inputString in str.windowed(length, 1)) {
                for (key in inputString) {
                    if (inputString.count { it == key } != 1) {
                        continue@Search
                    }
                }
                return length
            }
        }
        return -1
    }

    @Test
    fun test1() {
        val str = "abcabcbb"
        val result = RepetitionsString().repetitionsString(str)
        assertEquals(3, result)
    }

    @Test
    fun test2() {
        val str = "bbbbb"
        val result = RepetitionsString().repetitionsString(str)
        assertEquals(1, result)
    }

    @Test
    fun test3() {
        val str = "pwwkew"
        val result = RepetitionsString().repetitionsString(str)
        assertEquals(3, result)
    }
}